package com.igorkundovic.guitarstab.pages;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;


import com.igorkundovic.guitarstab.User;
import com.igorkundovic.guitarstab.service.UserService;

public class ChangeUserInfo {

	@Property
	@ApplicationState
	private User user;
	private boolean userExists;
	
	@InjectPage
	private UserInfo userInfo;
	
	@Inject
	private UserService userService;
	
	public Object onActivate(){
		if(userExists){
			return null;
		}
		return Welcome.class;
	}
	
	@OnEvent(component="userUpdate")
	public Object update(){
		boolean changed=userService.changeUserInfo(user);
		if(changed){
			return userInfo;
		}
		else{
			return this;
		}
	}
}
